﻿using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace Pibby.Controls
{
	public class EmptyListView : ListViewEx
	{
		const int DrawBackground = 20;

		//[TestCategory("Data")]
		[Description("Specifies the caption when the list is empty")]
		[DefaultValue("No items available")]
		[Browsable(true)]
		public string MessageWhenEmpty
		{
			get;
			set;
		}

		protected override void WndProc(ref Message m)
		{
			base.WndProc(ref m);

			if (m.Msg == DrawBackground)
			{
				if (this.Items.Count == 0)
				{
					Graphics g = this.CreateGraphics();
					string msg = MessageWhenEmpty;

					if (!string.IsNullOrEmpty(msg))
					{
						int width = (this.Width - g.MeasureString(msg, this.Font).ToSize().Width) / 2;
						g.DrawString(msg, this.Font, SystemBrushes.ControlText, width, 30);
					}
				}
			}
		}


	}
}
